package com.huafeng.commonutil;

import org.apache.commons.lang3.StringUtils;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 花风
 * @date 2023/8/16 10:48
 * @Description 获取token的工具类
 */
public class TokenUtils {
    public static String getToken(String tokenName){
        RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
        HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
        String token = request.getHeader(tokenName);
        return StringUtils.isNotEmpty(token) && StringUtils.isNotBlank(token) ? token : "";
    }
}
